using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AppManagement.Repositories
{
	#region using
	using AppManagement.Models;
	#endregion
	public class BenhPhamRepository
	{
		public static List<BenhPham> SelectAll()
		{
			return DataContext.Instance.BenhPhams.OrderBy(item => item.TenBP).ToList();
		}

		public static BenhPham SelectByID(string mabp)
		{
			return DataContext.Instance.BenhPhams.FirstOrDefault(item => item.MaBP == mabp );
		}

		public static bool Insert(BenhPham obj)
		{
			try
			{
				DataContext.Instance.BenhPhams.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(string mabp)
		{
			try
			{
				var delitem = DataContext.Instance.BenhPhams.FirstOrDefault(item => item.MaBP == mabp );
				DataContext.Instance.BenhPhams.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<BenhPham> RetrieveByID(string mabp)
		{
			return (from item in DataContext.Instance.BenhPhams where  item.MaBP == mabp  select item).ToList();
		}

	}
}